//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft
// premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license
// agreement, you are not authorized to use this source code.
// For the terms of the license, please see the license agreement
// signed by you and Microsoft.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
// Unit test code for the RegisterXRObject functionality in Alchemy
//
#pragma once

#define DEFINE_ENUM_PROPERTY_AS_STRING(ClassName, PropertyName, Enum, EnumAsStringArray) \
DEPENDENCY_PROPERTY_ID ClassName::s_##PropertyName##Id;\
HRESULT ClassName::Set##PropertyName(__in Enum Value)\
{\
    UINT enumMax = 0, index = 0;\
    HRESULT hr = E_FAIL;\
    enumMax = _countof(EnumAsStringArray);\
    index = (UINT)(Value);\
    if(index < enumMax)\
    {\
        hr = XRAttachedObject::SetDependencyProperty(s_##PropertyName##Id, EnumAsStringArray[index]);\
    }\
    return hr;\
}\
HRESULT ClassName::Get##PropertyName(__out Enum *pValue)\
{\
    ce::auto_bstr pValueString;\
    UINT enumMax = 0, value = 0;\
    HRESULT hr = E_FAIL;\
    if(NULL == pValue)\
    {\
        hr = E_POINTER;\
        goto Error;\
    }\
    hr = XRAttachedObject::GetDependencyProperty(s_##PropertyName##Id, &pValueString);\
    if(SUCCEEDED(hr))\
    {\
        if(NULL == pValueString)\
        {\
            hr = E_FAIL;\
            goto Error;\
        }\
        enumMax = _countof(EnumAsStringArray);\
        hr = E_FAIL;\
        for (value=0; value<enumMax; value++)\
        {\
            if (0 == wcscmp(EnumAsStringArray[value], pValueString))\
            {\
                *pValue = (Enum)value;\
                hr = S_OK;\
                break;\
            }\
        }\
    }\
Error:\
    return hr;\
}\

